package indi.gao.thread.future;

import java.util.concurrent.BlockingQueue;
import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author :gaolei
 * @version :v1.0
 * @projectName :GLUtil
 * @description :
 * @createDate :2021/8/9 3:21 下午
 */
public class FutureTestRejectPolicy implements RejectedExecutionHandler {
    @Override
    public void rejectedExecution(Runnable r, ThreadPoolExecutor executor) {
        BlockingQueue<Runnable> queue = executor.getQueue();
        System.out.println(queue.size());
        System.out.println(Thread.currentThread().getName());
//        try {
//            queue.put(r);
//        } catch (InterruptedException e) {
//            e.printStackTrace();
//        }
        new ThreadPoolExecutor.CallerRunsPolicy().rejectedExecution(r,executor);
    }
}
